package pw.hais.main.main_app.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import pw.hais.app.AppAdapter;
import pw.hais.http.Http;
import pw.hais.main.R;
import pw.hais.main.main_app.model.NeiHan8ArticleModel;
import pw.hais.utils.EmptyUtil;

/**
 * 菜单列表
 * Created by Hais1992 on 2015/12/14.
 */
public class HaiHanModelAdapter extends AppAdapter<NeiHan8ArticleModel, HaiHanModelAdapter.ViewHolder> {


    public HaiHanModelAdapter(List<NeiHan8ArticleModel> mList, Class<ViewHolder> mHolderClass) {
        super(mList, R.layout.activity_haihan_article_list_item, mHolderClass);
    }

    @Override
    public void onBindView(int position, ViewHolder mViewHolder, NeiHan8ArticleModel mItem) {
        if(EmptyUtil.emptyOfString(mItem.image_url)){
            mViewHolder.image_image.setVisibility(View.GONE);
            mViewHolder.text_title.setVisibility(View.VISIBLE);
            mViewHolder.text_title.setText(mItem.title);
            mViewHolder.text_content.setText(mItem.content+"...");
            mViewHolder.text_ct.setText("来源：网络收集");
        }else{
            mViewHolder.image_image.setVisibility(View.VISIBLE);
            Http.displayImage(mViewHolder.image_image,mItem.image_url);
            mViewHolder.text_title.setVisibility(View.GONE);
            mViewHolder.text_content.setText(mItem.content+"...");
            mViewHolder.text_ct.setText("来源：网络收集");
        }

    }

    //反射免FindViewById，名称必须和 XML的 控件ID一样
    public static class ViewHolder extends AppAdapter.ViewHolder {
        public TextView text_title;
        public TextView text_content;
        public TextView text_ct;
        public ImageView image_btn_share;
        public ImageView image_image;
    }
}
